﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace WebApp3
{
    public partial class frmUserBianji : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                string s;
                s = Request.QueryString["id"];
                string strCn = "server=pc.hstc.cn;database=dhd2014112111;uid=2014112111;pwd=19950511";
                SqlConnection cn = new SqlConnection(strCn);
                cn.Open();
                string strSql = "SELECT   lyzhuti, lyneirong, name, lytime, face, lyip, id, ReyTime, ReyNeirong, ReyName  FROM      LyTable   WHERE   (id = N'" + s + "')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();

                GridView1.DataSource = dr;
                GridView1.DataBind();
            }
            if (!Page.IsPostBack)
            {
                for (int i = 1; i < 79; i++)
                    ddl_head.Items.Add("表情" + i);
                img_head.ImageUrl = "~\\face\\1.gif";
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            img_head.ImageUrl = "~\\face\\" + (ddl_head.SelectedIndex + 1) + ".gif";
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                string s;
                s = Request.QueryString["id"];
                string strCn = "server=pc.hstc.cn;database=dhd2014112111;uid=2014112111;pwd=19950511";
                SqlConnection cn = new SqlConnection(strCn);
                try
                {
                    cn.Open();
                    string strSql = "UPDATE  LyTable SET           lyzhuti =  N'" + TextBox1.Text + "' ,lyneirong = N'" + TextBox2.Text + "'  ,face = N'" + (ddl_head.SelectedIndex + 1).ToString() + "'  WHERE   (id = N'" + s + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    int iUpd = cmd.ExecuteNonQuery();
                    if (iUpd < 1)
                    {
                        Response.Write("<script>alert('修改失败！');location.href='frmUserbianjiliuyan.aspx';</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('修改成功！');location.href='frmUserbianjiliuyan.aspx';</script>");

                    }

                }
                catch (Exception ex)
                {

                    this.lblOk.Text = ex.Message;
                }
                finally
                {
                    cn.Close();
                }
            }
        }

     

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] == null)
            {
                Page.Theme = "浅蓝色";
            }
            else if (Session["Theme"] == "浅蓝色")
            {
                Page.Theme = "浅蓝色";
            }
            else if (Session["Theme"] == "绿色")
            {
                Page.Theme = "绿色";
            }
            else if (Session["Theme"] == "黄色")
            {
                Page.Theme = "黄色";
            }
            else
            {
                Page.Theme = "红色";
            }
        }
    }
}